<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">
	
	<div class="container-div ui-layout-center">
		<div class="row">
			<!-- <div class="col-sm-12 select-info">
				<form id="operlog-form">
					<input type="hidden" id="deptId" name="deptId">
	                <input type="hidden" id="parentId" name="parentId">
					<div class="select-list gd">
						<ul>
							<li>
								登录名称：<input type="text" name="loginName"/>
							</li>
							<li>
								手机号码：<input type="text" name="phonenumber"/>
							</li>
							<li>
								用户状态：<select name="status" th:with="type=${@dictService.selectDictData('sys_normal_disable')}">
									<option value="">所有</option>
									<option th:each="e : ${type}" th:text="${e['dictLabel']}" th:value="${e['dictValue']}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search($('form').attr('id'))"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.exportExcel($('form').attr('id'))"><i class="fa fa-download"></i>&nbsp;下载</a>
							</li>
						</ul>
					</div>
				</form>
			</div> -->
	        
	        <div class="col-sm-12 select-info order-table">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<div th:include="include :: footer"></div>
	<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:inline="javascript">
		var editFlag = [[${@permissionService.hasPermi('system:user:edit')}]];
		var removeFlag = [[${@permissionService.hasPermi('system:user:remove')}]];
		var acceptFlag = [[${@permissionService.hasPermi('system:user:proposer:accept')}]];
		var prefix = ctx + "system/user"

		$(document).ready(function(){
			$('body').layout({ west__size: 185 });
			queryUserList();
		});

		function queryUserList() {
		    var options = {
		        url: prefix + "/proposer/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "用户",
		        search: false,
		        showExport: false,
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'userId',
		            title: '用户ID'
		        },
		        {
		            field: 'loginName',
		            title: '登录名称',
		            sortable: true
		        },
		        {
		            field: 'userName',
		            title: '真实姓名'
		        },
		        {
		        	field: 'sex',
		        	title: '性别',
		        	formatter: function(value, row, index){
		        		var sex;
		        		switch(value){
		        			case '0':
		        				sex='男'
			        			break;	
		        			case '1':
		        				sex='女'
		        				break;
		        			case '2':
		        				sex='未知'
		        				break;
		        		}
		        		return sex;
		        	}
		        },
		        {
		            field: 'phonenumber',
		            title: '手机'
		        },
		        {
		        	field: 'idCardNo',
		        	title: '身份证号'
		        },
		        {
		        	field: 'age',
		        	title: '年龄',
		        	align: 'center',
		        	formatter: function(value, row, index){
		        		if(value >= 18){
		        			return '<span class="badge badge-primary">'+value+'岁 成年</span>';
		        		}else{
		        			return '<span class="badge badge-danger">'+value+'岁 未成年</span>';
		        		}
		        	}
		        },
		        {
		            field: 'status',
		            title: '状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		                if (value == '0') {
		                    return '<span class="badge badge-primary">已激活</span>';
		                } else if (value == '2') {
		                    return '<span class="badge badge-danger">未激活</span>';
		                }
		            }
		        },
		        {
		            field: 'createDateTimeStr',
		            title: '申请时间',
		            formatter: function(value, row, index){
		        		return value.toString().substr(0,10);
		        	}
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-info btn-xs" href="#" onclick="accept(\'' + row.userId + '\')"><i class="fa fa-key"></i>批准</a>&nbsp;');
		                actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="notAccept(\'' + row.userId + '\')"><i class="fa fa-key"></i>不批准</a>');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		}
	
	function accept(userId){
		layer.confirm("确定激活账号吗?", function(index){
			$.ajax({
				url: prefix+'/proposer/accept',
				dataType: 'json',
				type: 'post',
				data: {"userId": userId},
				success: function(data){
					if(data.code == 0){
						message("账号激活成功");
						location.reload();
					}else{
						message("账号激活失败")
					}
				},
				error: function(data){
					layer.msg("请求失败");			
				}
			});
		});
	}
	
	function notAccept(userId){
		layer.confirm("确定驳回账号吗?", function(index){
			$.ajax({
				url: prefix+'/proposer/notAccept',
				dataType: 'json',
				type: 'post',
				data: {"userId": userId},
				success: function(data){
					if(data.code == 0){
						message("账号驳回成功");
						location.reload();
					}else{
						message("账号驳回失败")
					}
				},
				error: function(data){
					layer.msg("请求失败");			
				}
			});
		});
	}
	
	  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){
          layer.closeAll();
        }
      });
  }

	</script>
</body>
</html>